﻿using System.Buffers;

namespace Acl.Messages;

/// <summary>
/// 分布式rpc 接口定义,通过中介管道发送一个请求，由单个处理程序处理。
/// </summary>
public interface IDistributionSender
{
    /// <summary>
    ///    请求并接收一个响应结果
    /// </summary>
    /// <typeparam name="TRequest"></typeparam>
    /// <typeparam name="TReplay"></typeparam>
    /// <param name="topic"></param>
    /// <param name="data"></param>
    /// <param name="reqestOpts"></param>
    /// <param name="replyOpts"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    ValueTask<IDistributionMessage<TReplay?>?> Send<TRequest,TReplay>(string topic,
        TRequest data, 
        DistributionPublishOptions? reqestOpts = default,
        DistributionSubscribeOptions? replyOpts = default,
        CancellationToken cancellationToken = default);

   
    /// <summary>
    ///  请求并接收一组响应结果
    /// </summary>
    /// <typeparam name="TRequest"></typeparam>
    /// <typeparam name="TReply"></typeparam>
    /// <param name="topic"></param>
    /// <param name="data"></param>
    /// <param name="reqestOpts"></param>
    /// <param name="replyOpts"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    IAsyncEnumerable<IDistributionMessage<TReply?>> RequestManyAsync<TRequest, TReply>(string topic,
        TRequest data,
        DistributionPublishOptions? reqestOpts = default,
        DistributionSubscribeOptions? replyOpts = default,
        CancellationToken cancellationToken = default);

   
}
